package com.mazaiting.ocr

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.module.annotations.ReactModule
import android.support.v4.app.ActivityCompat.startActivityForResult
import com.baidu.ocr.ui.camera.CameraActivity
import android.content.Intent


/**
 * OCR识别界面
 * Created by mazaiting on 2018/9/21.
 */
@ReactModule(name = "OcrModule")
class OcrModule (val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext){
  override fun getName(): String = "OcrModule"
  companion object {
    private val REQUEST_CODE_CAMERA = 102
  }
  
  @ReactMethod
  fun startOcrActivity() {
    val intent = Intent(currentActivity, com.baidu.ocr.ui.camera.CameraActivity::class.java)
    intent.putExtra(CameraActivity.KEY_OUTPUT_FILE_PATH,
            FileUtil.getSaveFile(reactApplicationContext).absolutePath)
    intent.putExtra(CameraActivity.KEY_CONTENT_TYPE, CameraActivity.CONTENT_TYPE_ID_CARD_FRONT)
    currentActivity?.startActivityForResult(intent, REQUEST_CODE_CAMERA)
  }
  
}